﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HelloWPF.Study.Windows
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {
        MainViewModel viewModel = new MainViewModel();
        public MainWindow()
        {
            InitializeComponent();

            //1.通过委托View和ViewModel解耦
            //viewModel.ShowPopup = new Action(() =>
            //{
            //    PopupWindow popupWindow = new PopupWindow();
            //    popupWindow.ShowDialog();
            //});

            //1.通过委托View和ViewModel解耦，带返回值
            //viewModel.ShowPopupFunc = new Func<PopupModel, bool>(model =>
            //{
            //    PopupWindow popupWindow = new PopupWindow();
            //    popupWindow.Owner = this;
            //    popupWindow.DataContext = model;
            //    return popupWindow.ShowDialog() == true;
            //});

            //2.通过第三方窗口容器View和ViewModel解耦
            WindowContainer.Register<PopupWindow>("PopupWindow", this);

            this.DataContext = viewModel;
        }
    }
}
